$(function () {
    //新三级树
    // 线获取添加模板基本信息
    $.get(baseURL + "goodsCategory/goodscategory/getCategoryTree", function(r){
        vm.categoryTree = r.addInfo.categoryTree;
    });
    /* oss上传 */
    $.files_up_oss({
        id: ["upload1", "upload2","upload3"],//按钮id
        url: "/sys/oss/getSignature",
        dir: "test/pop/goods/goodsImages/",
        file_type: "jpg,png,gif,psd,ai,cdr,eps,ppt,word,excel,pdf,tiff,rar,zip,7z,gif,AVI,WMV,RM,RMVB,MPEG1,MPEG2,MPEG4,3GP,ASF,SWF,VOB,DAT,MOV,M4V,FLV,F4V,MKV,TIF",
        size: "100mb",//mb
        view_url: "https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/"
    }, function (index_number, json) {
        if (json.Status == 'OK') {
            // $('#image' + (index_number + 1)).attr('src', 'https://ziyunoss.oss-cn-hangzhou.aliyuncs.com/' + json.filename);
            //将文件信息存放到图片集中
            if (index_number == 0) {
                //商品默认图片
                vm.goodsImage.imageUrl = json.filename;
                vm.goodsImage.type = 0;
                $.ajax({
                    type: "POST",
                    url: baseURL + "goodsImage/goodsimage/saveImage",
                    contentType: "application/json",
                    data: JSON.stringify(vm.goodsImage),
                    success: function (r) {
                        if (r.code === 0) {
                            vm.imageIds.push(r.id);
                            vm.imageUrls.push({"filename": json.filename, "fileId": r.id});
                            // console.info(vm.imageUrls)
                            // alert("上传图片成功")
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            } else if(index_number == 1){
                //商品详细介绍图片
                vm.goodsImage.imageUrl = json.filename;
                vm.goodsImage.type = 1;
                $.ajax({
                    type: "POST",
                    url: baseURL + "goodsImage/goodsimage/saveImage",
                    contentType: "application/json",
                    data: JSON.stringify(vm.goodsImage),
                    success: function (r) {
                        if (r.code === 0) {
                            vm.infoIds.push(r.id);
                            vm.infoUrls.push({"filename": json.filename, "fileId": r.id});
                            // alert("上传图片成功")
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            } else{//上传视频
                vm.goodsImage.imageUrl = json.filename;
                vm.goodsImage.type = 3;
                $.ajax({
                    type: "POST",
                    url: baseURL + "goodsImage/goodsimage/saveImage",
                    contentType: "application/json",
                    data: JSON.stringify(vm.goodsImage),
                    success: function (r) {
                        if (r.code === 0) {
                            // vm.infoIds.push(r.id);
                            vm.good.videoUrl = r.id;
                            vm.videoUrl = {"filename": json.filename, "fileId": r.id};
                            // vm.infoUrls.push({"filename": json.filename, "fileId": r.id});
                            // alert("上传图片成功")
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            }
        } else {
            alert("出现异常,请联系管理员!")
        }
        alert("上传图片成功")
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        //测试
        value10:[],
        select:[],
        pushGoodOne: true,
        pushGoodTwo: false,
        categoryId: null, //分类id
        categoryTree:[], //商品分类树
        //三级分类选择器
        cat1: '', cat2: '',cat3:'', categoryList1: {}, categoryList2: {}, categoryList3: {},
        goodsCategoryDialogVisible: false,// 商品分类树弹窗
        //展示分类名和模板对象和分类信息
        categoryNames: null, goodTemplate: {}, categoryEntity: {},
        //商品规格和工艺选择结果展示
        attributeNames: [], craftNames: [],
        //弹窗规格/工艺选择器
        // attributes:{},selected:[],
        //规格layer选择器容器,弹窗数据装载
        attributeList: [],
        copyAttributeList:[],
        craftAttributeList: [],
        copyCraftAttributeList: [],
        //默认图片_详细图片
        imageUrls: [], infoUrls: [],
        //图片id容器
        imageIds: [], infoIds: [],
        //图片上传暂存容器
        goodsImage: {},
        //layer规格工艺选择值集合
        map: {
            attributeMap: {},
            craftAttributeMap: {}
        },
        //运费模板信息
        freightTemplates: {},
        //单纯的配价ids
        craftIds:null,
        //品牌信息
        goodBrands: {},
        good: {
            specificationItems: [],
            craftAttributes: [],
            marketable: 'puton',
            noStore: 'false',
            freightId: '',
            brandId: '',
            marketable: 'puton',
            disabled: false,
            videoUrl:'',
            itemList : [{spec: {},cra: {},store: '',unit: '',minBuyNum: '',marketable: 'puton',weight: '',totalPrice: '',
                marketPrice: '',expandPrice: '',lMarketPrice: '',cost: '',lCost: '',defaultProduct: false}],
            joinSkuOptionIds:[],
            ratio:null,
            // reward:false,
            examineStatus:0,
            // itemList:[{spec:{},store:'',weight:'',totalPrice:'',marketPrice:''}]
            stepPrice:null,
            popStepPrice:null,

        },
        //设计服务查询器
        designQuery: {
            spu: '',
            name: ''
        },
        //设计服务容器
        designGood: {},
        //----------------------------------------------印刷
        quoteAttributeList: [],
        quoteCraftAttributeList:[],
        //-----------------------以上可能废弃
        allQuoteTemplate:[],
        copyAllQuoteTemplate:[],
        recordAllQuoteTemplate:[],
        quoteAttributeLayer:false,
        quoteSelected:[],
        defaultSelected:[],
        quoteCraftSelected:[],
        craftDefaultSelected:[],
        marketables:[
            {key:'puton',value:'上架'},{key:'pulloff',value:'下架'},{key:'delete',value:'删除'}
        ],
        machinePriceLayer:false,
        materialPriceLayer:false,
        craftPriceLayer:false,
        fastGroupPricelayer:false,
        attributeAndCraftLayer:false,
        freightLayer:false,
        //自定义选项dialog
        addOptionDialog:false,
        materialDefaultOptions:[],
        //craftdata--materialData
        craftdata:[],
        materialData:[],
        attributeVo:[],
        //无关的工艺选项
        alwaysCraftOptions:[],
        canPush:true,
        sellerInfo:null,
        price:null,
        addPrivateOption:{
            optionName:null,
            optionValue:null,
        },
        //单位库list
        unitLibraryList:null,
        priceDialog:false,
        stepPriceList:[],
        stepType:null,
    },
    watch: {
        cat1(val, oldVal) {
            //请求后台获得二级分类
            $.get(baseURL + "goodsCategory/goodscategory/getSonCategory/" + val, function (r) {
                vm.categoryList2 = r.goodsCategoryList;
            });
            vm.categoryList3 = {};
        },
        cat2(val, oldVal) {
            //请求后台获得三级分类
            $.get(baseURL + "goodsCategory/goodscategory/getSonCategory/" + val, function (r) {
                vm.categoryList3 = r.goodsCategoryList;
            });
            vm.cat3 = '';
        },
        cat3(val, oldVal){
            vm.good.categoryId = val;
            // if(vm.cat3!=''){
            vm.findGoodTwo();
            // }
        }
    },
    methods: {
        choiceCategory:function(){
            vm.goodsCategoryDialogVisible = true;
        },
        //树结构选中变化时
        categoryChange:function(value){
            //取到末级的分类id
            vm.good.categoryId = value[value.length-1];
            //调用接下来的步骤
            vm.findGoodTwo();
            vm.goodsCategoryDialogVisible = false;
        },
        //确认三级分类,选择下一步
        findGoodTwo: function () {
            // vm.pushGoodOne = false;
            // vm.pushGoodTwo = true;
            //获得三级分类全称
            $.get(baseURL + "goodsCategory/goodscategory/getCatNames/" + vm.good.categoryId, function (r) {
                if(r.code == 0){
                    vm.categoryNames = r.categoryNames;
                    vm.unitLibraryList = r.unitLibraryList;
                    vm.sellerInfo = r.sellerInfo;
                    if(r.categoryEntity.goodsType == 'standard' || r.categoryEntity.goodsType == 'paper'|| r.categoryEntity.goodsType == 'copy'||r.categoryEntity.goodsType == 'design'||r.categoryEntity.goodsType == 'material'){
                        if(isBlank(r.goodTemplate)){
                            alert('该分类下未绑定模板,商品无法发布', '温馨提示');
                            return;
                        }
                        if(r.goodTemplate.dateTemp){
                            alert('该模板暂未启用!', '温馨提示');
                            return;
                        }
                        vm.goodTemplate = r.goodTemplate;
                    }
                    vm.categoryEntity = r.categoryEntity;
                    //获得规格模板对象
                    var categoryId = vm.categoryEntity.categoryId
                    // if (vm.categoryEntity.goodType == 'paper') {
                    //设置商品类型为大纸
                    vm.good.goodsType = vm.categoryEntity.goodsType;
                    // }
                    //判断商品类型
                    if(vm.categoryEntity.goodsType == 'standard' || vm.categoryEntity.goodsType == 'paper'|| vm.categoryEntity.goodsType == 'copy'||r.categoryEntity.goodsType == 'design'||r.categoryEntity.goodsType == 'material'){
                        //按商品模板查找其中的规格属性及其规格属性值展示
                        $.get(baseURL + "goods/goodsattribute/getAttributesByTemplateId/" + vm.goodTemplate.templateId, function (r) {
                            if(r.code == 0){
                                vm.attributeList = r.attributeList;
                                vm.craftAttributeList = r.craftAttributeList;
                                //深克隆
                                vm.copyAttributeList = JSON.parse(JSON.stringify(r.attributeList));
                                vm.copyCraftAttributeList = JSON.parse(JSON.stringify(r.craftAttributeList));
                            }else{
                                alert(r.msg)
                            }
                        });
                        // //按商品模板查找其中的规格属性及其规格属性值展示
                        // $.get(baseURL + "goods/goodsattribute/getCraftAttributesByTemplateId/" + vm.goodTemplate.templateId, function (r) {
                        //     vm.craftAttributeList = r.craftAttributeList;
                        // });
                    }else{
                        var categoryId = vm.good.categoryId;
                        //当身份是小b且发布的是商务印刷的时候,暂不让发布
                        if(vm.sellerInfo.sellerType == 0 && vm.categoryEntity.goodsType == 'print'){
                            alert("商务印刷类商品发布将在近期对供应商开发!")
                            return;
                        }
                        //报价商品加载模板请求
                        $.get(baseURL + "goods/goods/quoteTemplate/" + categoryId, function (r) {
                            vm.allQuoteTemplate = r.allQuoteTemplate;
                            //报价商品数据读档,用以筛选是否配价
                            //var newRow = JSON.parse(JSON.stringify(oldRow));//深克隆
                            vm.recordAllQuoteTemplate = JSON.parse(JSON.stringify(r.allQuoteTemplate));
                            vm.copyAllQuoteTemplate = JSON.parse(JSON.stringify(r.allQuoteTemplate));
                        });
                    }
                }else{
                    alert(r.msg)
                }
            });

            //加载运费模板
            $.get(baseURL + "freightages/freighttemplate/allList", function (r) {
                vm.freightTemplates = r.freightTemplateList;
            });
            //获得品牌列表
            $.get(baseURL + "goods/goodsbrand/allList", function (r) {
                vm.goodBrands = r.brandEntityList;
            });
        },
        //保存商品,发布提交
        saveGood: function () {
            //将图片路径转换为字符串存储
            vm.good.imageUrls = vm.imageIds.join(",");
            vm.good.infoUrls = vm.infoIds.join(",");
            vm.good.attributeNames = vm.attributeNames.join(",");
            vm.good.craftNames = vm.craftNames.join(",");
            //根据分类确定goods_type
            vm.good.goodsType = vm.categoryEntity.goodsType;
            //-----------------------------------
            if(vm.good.goodsType == 'standard' || vm.good.goodsType == 'paper' || vm.good.goodsType == 'copy' || vm.good.goodsType == 'material'   || vm.good.goodsType == 'design' ){
                if (vm.validator()) {
                    return;
                }
                var optionIdList = [];
                for(var i = 0;i<vm.good.itemList.length;i++){
                    var optionIds = [];
                    for(var j = 0;j<vm.good.itemList[i].spec.length;j++){
                        optionIds.push(vm.good.itemList[i].spec[j].optionId)
                    }
                    optionIdList.push(optionIds)
                }
                var verifyPriceVo = {};
                verifyPriceVo.templateId = vm.goodTemplate.templateId;
                verifyPriceVo.craftIds = vm.craftIds;
                verifyPriceVo.attributeVoList = vm.attributeVo;
                verifyPriceVo.alwaysCraftOptions = vm.alwaysCraftOptions;
                console.info(JSON.stringify(verifyPriceVo));
                $.ajax({
                    type: "POST",
                    url: baseURL + "goods/goods/verifyCraftPrice",
                    contentType: "application/json",
                    data: JSON.stringify(verifyPriceVo),
                    success: function (r) {
                        if(r.msg != 'ok'){
                            alert(r.msg);
                            return;
                        }
                        $.ajax({
                            type: "POST",
                            url: baseURL + "goods/goods/pushGood",
                            contentType: "application/json",
                            data: JSON.stringify(vm.good),
                            beforeSend: function () {
                                $("#saveBtn").attr({disabled:"disabled"});
                                console.info("按钮已经被禁用")
                            },
                            complete:function(){
                                $("#saveBtn").removeAttr("disabled");
                                console.info("按钮已经被恢复")
                            },
                            success: function (r) {
                                if (r.code === 0) {
                                    // alert('操作成功');
                                    console.info("发布成功")
                                    //页面跳转
                                    window.location.href = "/modules/goods/goods.html";
                                } else {
                                    this.$message({
                                        type: 'info',
                                        message: r.message,
                                    });
                                }
                            }
                        });
                    }
                });
            }else if(vm.good.goodsType == 'print'|| vm.good.goodsType == 'fast'){
                if(vm.quoteVala()){
                    return;
                }
                //-----------------------发布报价商品
                // if (vm.quotevalidator()) {
                //     console.info("返回,停止发布")
                //     return;
                // }
                if(vm.canPush){
                    this.$message({
                        type: 'info',
                        message: "有参数不全,不能发布"
                    });
                    return ;
                }
                console.info("开始发布")
                //发布报价商品
                console.info(vm.allQuoteTemplate)
                var quoteVo = {};
                quoteVo.goodsEntity = vm.good;
                //QuoteVo.quoteProductBaseInfoVOList
                var list = [];
                for(var i = 0;i<vm.allQuoteTemplate.length;i++){
                    var QuoteProductBaseInfoVO = {};
                    //遍历普通
                    var tempList = [];
                    for(var j = 0;j<vm.allQuoteTemplate[i].normalAttributeOptionList.length;j++){
                        if(vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalSelectedTempOptionList.length>0){
                            var tempObject = {};
                            //每一种规格的选项集合
                            tempObject.id = vm.allQuoteTemplate[i].normalAttributeOptionList[j].id;
                            tempObject.attributeName =vm.allQuoteTemplate[i].normalAttributeOptionList[j].attributeName;
                            var ids = [];
                            for(var v = 0;v<vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalSelectedTempOptionList.length;v++){
                                ids.push(vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalSelectedTempOptionList[v].id);
                            }
                            tempObject.normalSelectedOptionList = ids;
                            tempObject.normalDefaultOption = vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalDefaultOption;
                            tempList.push(tempObject);
                        }
                    }
                    QuoteProductBaseInfoVO.normalAttributeOptionSelectedList = tempList;
                    // list.push(tempList);
                    //遍历材料
                    var quoteTempList = []; //选中材料列表
                    if(JSON.stringify(vm.allQuoteTemplate[i].materialAttributeOptionData) != '{}'){
                        for(var j= 0;j<vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList.length;j++){
                            if(vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[j].materialSelectedOptionList.length>0){
                                //该材料有被选择
                                var tempObject = {};
                                tempObject.id = vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[j].id;//属性id
                                tempObject.attributeName = vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[j].attributeName;// 属性名称
                                tempObject.materialSelectedOptionList = vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[j].materialSelectedOptionList;//选中的材料选项
                                quoteTempList.push(tempObject);
                            }
                        }
                    }
                    QuoteProductBaseInfoVO.materialAttributeOptionSelectedList = quoteTempList;
                    QuoteProductBaseInfoVO.materialDefaultOptionName2 = vm.allQuoteTemplate[i].materialAttributeOptionData.materialDefaultOptionName2;
                    QuoteProductBaseInfoVO.categoryId = vm.allQuoteTemplate[i].categoryId;
                    QuoteProductBaseInfoVO.partsId = vm.allQuoteTemplate[i].partsId;
                    list.push(QuoteProductBaseInfoVO);
                }
                quoteVo.quoteProductBaseInfoVOList = list;
                //发布报价商品;
                //下列需要方法改装
                $.ajax({
                    type: "POST",
                    url: baseURL + "goods/goods/pushQuoteGood",
                    contentType: "application/json",
                    data: JSON.stringify(quoteVo),
                    beforeSend: function () {
                        $("#saveBtn").attr({disabled:"disabled"});
                        console.info("按钮已经被禁用")
                    },
                    complete:function(){
                        $("#saveBtn").removeAttr("disabled");
                        console.info("按钮已经被恢复")
                    },
                    success: function (r) {
                        if (r.code === 0) {
                            // alert('操作成功', function (index) {
                            // });
                            //页面跳转
                            window.location.href = "/modules/goods/goods.html";
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            }
        },
        //新版本规格工艺选择
        choiceNewAttributeAndCraft:function(){
            //判断大纸类的是否选择了平板或卷筒
            if(vm.categoryEntity.goodsType == 'paper' && isBlank(vm.good.isUnit)){
                alert("大纸类的请先选择卷筒or平板")
                return;
            }
            vm.attributeAndCraftLayer = true;
        },
        //取消的时候,给标品回滚
        rollBack:function(){
            // vm.copyAttributeList = r.attributeList;
            // vm.copyCraftAttributeList = r.craftAttributeList;
            //深克隆
            vm.attributeList = JSON.parse(JSON.stringify(vm.copyAttributeList));
            vm.craftAttributeList = JSON.parse(JSON.stringify(vm.copyCraftAttributeList));
        },
        //新版本规格工艺选择完生成矩阵数据原型
        builderDate:function(){
            //先初始化
            vm.attributeVo= [];
            vm.alwaysCraftOptions = [];
            ;
            var influence = JSON.parse(vm.goodTemplate.influenceCraftIds)
            for(var i = 0;i<influence.length;i++){
                // var influence = JSON.toJSON(vm.goodTemplate.influenceCraftIds)

                if(influence[i].attributeIds.length >0){
                    var attribute = {};
                    attribute.attributeId = influence[i].attributeIds[0];
                    attribute.craftId = influence[i].craftId;
                    vm.attributeVo.push(attribute);
                }
            }
            //第一步,选出被选中的规格和工艺
            var attributeDate = [];
            var craftDate = [];
            var craftIdsList = [];
            for(var i= 0;i<vm.attributeList.length;i++){
                var option = [];
                var attribute = {};
                var influenceOptionIds = [];
                attribute.attributeId = vm.attributeList[i].attributeId;
                attribute.attributeName = vm.attributeList[i].attributeName;
                //遍历被选中的option列表
                if(isBlank(vm.attributeList[i].optionSelectedList)){
                    alert("规格属性必须全部选择至少一项!")
                    return;
                }
                for(var j= 0;j<vm.attributeList[i].optionSelectedList.length;j++){
                    var op = vm.attributeList[i].optionSelectedList[j]
                    influenceOptionIds.push(op.optionId);
                    option.push({optionId:op.optionId,optionName:op.optionName})
                }
                if(vm.attributeVo.length>0){
                    ;
                    for(var kk = 0;kk<vm.attributeVo.length;kk++){
                        if(vm.attributeVo[kk].attributeId == vm.attributeList[i].attributeId){
                            //放入
                            vm.attributeVo[kk].optionIds = influenceOptionIds;
                        }
                    }
                }
                attributeDate.push({attribute:attribute,option:option});
            }
            //第二部,将参与sku生成的工艺提取
            var joinSkuOptionIds = [];
            for(var i = 0;i<vm.craftAttributeList.length;i++){
                //判断这个工艺是否参与
                if(vm.craftAttributeList[i].joinAttribute){
                    //该工艺参与sku的生产
                    var option = [];
                    var attribute = {};
                    var joinSkuOption = [];
                    var joinSkuAttribute = {};
                    attribute.attributeId = vm.craftAttributeList[i].attributeId;
                    attribute.attributeName = vm.craftAttributeList[i].attributeName;
                    //遍历被选中的option列表
                    for(var j= 0;j<vm.craftAttributeList[i].optionSelectedList.length;j++){
                        var op = vm.craftAttributeList[i].optionSelectedList[j]
                        option.push({optionId:op.optionId,optionName:op.optionName})
                        //将这部分参与sku生成的工艺选项标记
                        joinSkuOption.push(op.optionId)
                    }
                    joinSkuAttribute = vm.craftAttributeList[i].attributeId;
                    attributeDate.push({attribute:attribute,option:option});
                    joinSkuOptionIds.push({attribute:joinSkuAttribute,option:joinSkuOption})
                }else{
                    ;
                    if(!isBlank(vm.craftAttributeList[i].optionSelectedList) && vm.craftAttributeList[i].optionSelectedList.length > 0){
                        craftIdsList.push(vm.craftAttributeList[i].attributeId);
                    }
                    //套用以前的工艺生成方式
                    var option = [];
                    var attribute = {};
                    var influenceCraftOptionIds = [];
                    attribute.attributeId = vm.craftAttributeList[i].attributeId;
                    attribute.attributeName = vm.craftAttributeList[i].attributeName;
                    //vm.attributeVo
                    //遍历被选中的option列表
                    for(var j= 0;j<vm.craftAttributeList[i].optionSelectedList.length;j++){
                        var op = vm.craftAttributeList[i].optionSelectedList[j]
                        option.push({optionId:op.optionId,optionName:op.optionName})
                        ;
                        influenceCraftOptionIds.push(op.optionId);
                    }
                    var flag = true;
                    if(vm.attributeVo.length>0){
                        ;
                        for(var kk = 0;kk<vm.attributeVo.length;kk++){
                            if(vm.attributeVo[kk].craftId == vm.craftAttributeList[i].attributeId){
                                //放入
                                vm.attributeVo[kk].craftOptionIds = influenceCraftOptionIds;
                                flag = false;
                            }
                        }
                    }
                    if(flag){
                        if(influenceCraftOptionIds != null && influenceCraftOptionIds.length > 0){
                            for(var kkk =0;kkk< influenceCraftOptionIds.length;kkk++){
                                ;
                                vm.alwaysCraftOptions.push(influenceCraftOptionIds[kkk]);
                            }
                        }
                    }
                    craftDate.push({attribute:attribute,option:option})
                }
            }
            //第三部,组合数据出最终数据原型
            console.info("attributeDate:"+JSON.stringify(attributeDate));
            console.info("craftDate:"+JSON.stringify(craftDate));
            vm.craftIds = craftIdsList;
            vm.good.specificationItems = attributeDate;
            vm.good.craftAttributes = craftDate;
            vm.good.joinSkuOptionIds = joinSkuOptionIds;
            vm.createItemList();
            vm.addCraft();
            //--------------------------------------
            //数据建立完毕,赋值
            //深克隆
            vm.copyAttributeList = JSON.parse(JSON.stringify(vm.attributeList));
            vm.copyCraftAttributeList = JSON.parse(JSON.stringify(vm.craftAttributeList));
            //关闭
            vm.attributeAndCraftLayer = false;
            //

        },
        //规格属性选择
        chooseAttribute: function () {
            //如果是大纸商品,则需要先选择卷筒or平板
            if (vm.categoryEntity.goodsType == 'paper' && vm.good.isUnit == undefined) {
                alert("大纸商品请先选择卷筒or平板")
                return;
            }
            //layer弹窗
            layer.open({
                type: 1,
                skin: 'layui-layer-molv',
                title: "规格属性选择",
                area: ['900px', '400px'],
                shadeClose: false,
                content: jQuery("#attributeLayer"),
                btn: ['确定'],
                btn1: function () {
                    //更改规格模型
                    vm.createItemList();
                    //校验模板规格是否都选择了
                    var attrIds = [];
                    for (var i = 0; i < vm.good.specificationItems.length; i++) {
                        attrIds.push(vm.good.specificationItems[i].attribute.attributeId);
                    }
                    if (vm.attributeList.length != attrIds.length) {
                        alert("温馨提示,还有尚未选择的规格哦!")
                        return;
                    }
                    //关闭layer
                    layer.close(layer.index);
                },
                cancel: function (index, layero) {
                    confirm('取消将会重置规格属性,是否确认取消?', function(){
                        vm.good.specificationItems=[];
                        vm.createItemList();
                        layer.close(layer.index);
                    });
                    // vm.good.specificationItems=[];
                    // vm.createItemList();
                    // layer.close(layer.index);
                    return false;
                }
                // btn2:function(){
                //     vm.good.specificationItems = [];
                //     $("input[name='attr']").prop("checked",false);
                // }
            });
        },
        //工艺选择
        chooseCraft: function () {
            //判断是否先选择了规格属性
            if (JSON.stringify(vm.attributeNames) == '[]') {
                alert("请先选择规格属性!")
                return;
            }
            //按商品模板查找其中的规格属性及其规格属性值展示
            $.get(baseURL + "goods/goodsattribute/getCraftAttributesByTemplateId/" + vm.goodTemplate.templateId, function (r) {
                vm.craftAttributeList = r.craftAttributeList;
            });
            //layer弹窗
            layer.open({
                type: 1,
                skin: 'layui-layer-molv',
                title: "工艺属性选择",
                area: ['900px', '400px'],
                shadeClose: false,
                content: jQuery("#craftAttributeLayer"),
                btn: ['确定'],
                btn1: function () {
                    //遍历vm.good.itemList 朝每个item里添加一个工艺选择备案cra{}
                    vm.addCraft();
                    //关闭layer
                    layer.close(layer.index);
                }
                // btn2:function(){
                //     vm.good.craftAttributes = [];
                //     $("input[name='craft']").prop("checked",false);
                // }

            });
        },
        //规格弹窗选择结果处理
        choiceAttribute: function (event, attributeId, attributeName, optionId, optionName) {
            vm.updateSpecAttribute(event, attributeId, attributeName, optionId, optionName)
        },
        //工艺弹窗选择结果处理
        choiceCraft: function (event, attributeId, attributeName, optionId, optionName) {
            vm.updateCraftAttributes(event, attributeId, attributeName, optionId, optionName)
        },
        //在list集合中根据某key的值查询对象
        // vm.good.specificationItems={["attributeName":"","attributeValue",""]}
        // vm.good.specificationItems={["attribute":{attributeId:attributeName},"option":[{optionId:optionName}]]}

        //key-->attribute   keyValue-->{attributeId:attributeName}

        //当选择改变时,更新规格模型
        updateSpecAttribute: function (event, attributeId, attributeName, optionId, optionName) {
            //object = ["attributeName":"","attributeValue",""];
            var object = vm.searchObjectByKey(vm.good.specificationItems, 'attribute', {
                "attributeId": attributeId,
                "attributeName": attributeName
            });
            if (object != null) {
                if (event.target.checked) {
                    object.option.push({"optionId": optionId, "optionName": optionName});
                } else {//取消勾选
                    object.option.splice(object.option.indexOf({"optionId": optionId, "optionName": optionName}), 1);//移除选项
                    //如果选项都取消了，将此条记录移除
                    if (object.option.length == 0) {
                        vm.good.specificationItems.splice(vm.good.specificationItems.indexOf(object), 1);
                    }
                }
            } else {
                vm.good.specificationItems.push({
                    "attribute": {
                        "attributeId": attributeId,
                        "attributeName": attributeName
                    }, "option": [{"optionId": optionId, "optionName": optionName}]
                });
            }
        },
        //当选择改变时,更新工艺模型
        updateCraftAttributes: function (event, attributeId, attributeName, optionId, optionName) {
            //object = ["attributeName":"","attributeValue",""];
            var object = vm.searchObjectByKey(vm.good.craftAttributes, 'attribute', {
                "attributeId": attributeId,
                "attributeName": attributeName
            });
            if (object != null) {
                if (event.target.checked) {
                    object.option.push({"optionId": optionId, "optionName": optionName});
                } else {//取消勾选
                    object.option.splice(object.option.indexOf({"optionId": optionId, "optionName": optionName}), 1);//移除选项
                    //如果选项都取消了，将此条记录移除
                    if (object.option.length == 0) {
                        vm.good.craftAttributes.splice(vm.good.craftAttributes.indexOf(object), 1);
                    }
                }
            } else {
                vm.good.craftAttributes.push({
                    "attribute": {"attributeId": attributeId, "attributeName": attributeName},
                    "option": [{"optionId": optionId, "optionName": optionName}]
                });
            }
        },
        searchObjectByKey: function (list, key, keyValue) {
            for (var i = 0; i < list.length; i++) {
                if (JSON.stringify(list[i][key]) == JSON.stringify(keyValue)) {
                    return list[i];
                }
            }
            return null;
        },
        //创建SKU列表
        createItemList: function () {
            vm.good.itemList = [{
                spec: {},
                cra: {},
                store: '',
                unit: '',
                minBuyNum: '',
                marketable: 'puton',
                weight: '',
                totalPrice: '',
                totalPricePop: '',
                marketPrice: '',
                expandPrice: '',
                expandPricePop: '',
                lMarketPrice: '',
                cost: '',
                lCost: '',
                defaultProduct: false
            }]
            // vm.good.itemList=[{spec:{},price:0,num:99999,status:'0',isDefault:'0'} ];//列表初始化
            // vm.good.specificationItems={[{"attribute":{"attributeId":attributeId,"attributeName":attributeName}}
            //                              ,"option":[{"optionId":optionId,"optionName":optionName}]]}
            var items = vm.good.specificationItems;
            //item的长度是规格属性的个数
            for (var i = 0; i < items.length; i++) {
                vm.good.itemList = vm.addColumn(vm.good.itemList, items[i].attribute, items[i].option);
            }
            //创建完毕,为规格属性赋值
            var str = [];
            for (var i = 0; i < vm.good.specificationItems.length; i++) {
                str.push(vm.good.specificationItems[i].attribute.attributeName);
                // vm.attributeNames.push(vm.good.specificationItems[i].attribute.attributeName);
            }
            vm.attributeNames = str;
            console.info(vm.good.itemList)
        },
        //添加列数据
        //list:{"attribute":{"attributeId":attributeId,"attributeName":attributeName} ,"option":[{"optionId":optionId,"optionName":optionName}]}
        //columnName - attribute  ->{"attributeId":attributeId,"attributeName":attributeName}
        //columnValues - option ->[{"optionId":optionId,"optionName":optionName}]
        addColumn: function (list, columnName, columnValues) {
            var newList = [];
            //list的长度是需要克隆的记录条数
            for (var i = 0; i < list.length; i++) {
                var oldRow = list[i];
                //columnValues是每个规格属性选择值的个数
                for (var j = 0; j < columnValues.length; j++) {
                    var newRow = JSON.parse(JSON.stringify(oldRow));//深克隆
                    newRow.spec[columnName.attributeName] = columnValues[j];
                    newList.push(newRow);
                }
            }
            //vm.good.itemList[0].spec=[规格1:规格值1,规格2:规格值2]
            //vm.good.itemList[0].spec={"attribute":{"attributeId":attributeId,"attributeName":attributeName}
            //                           ,"option":{"optionId":optionId,"optionName":optionName}}
            return newList;
        },
        //向vm.good.itemList 的每一个item对象,添加一个cra{}
        addCraft: function () {
            //选择完成后的结果,用以装载进vm.good.itemList中的cra{}
            // var items= vm.good.craftAttributes;
            var items = vm.good.itemList;
            for (var i = 0; i < items.length; i++) {
                items[i].cra = vm.good.craftAttributes;
            }
            // for(var i=0;i<items.length;i++){
            //     vm.good.itemList= vm.addColumn( vm.good.itemList, items[i].attribute,items[i].option );
            // }
            //将选择结果返回展示
            for (var i = 0; i < vm.good.craftAttributes.length; i++) {
                vm.craftNames.push(vm.good.craftAttributes[i].attribute.attributeName);
            }

        },
        //设计服务选择
        addDesign: function () {
            vm.designQuery = {spu: '', name: ''}
            vm.myDesignQuery();
            layer.open({
                type: 1,
                skin: 'layui-layer-molv',
                title: "关联设计服务",
                area: ['510px', '500px'],
                shadeClose: false,
                content: jQuery("#designLayer"),
                btn: ['确定', '取消'],
                btn1: function () {
                    var designId = $("#designJqGrid").getGridParam("selrow");
                    // //下列判断需完善
                    if (designId == null) {
                        return;
                    }
                    //将该设计商品的goodsId绑定在good模型上
                    vm.good.relateDesignIds = designId;
                    console.info(designId);
                    //获得designGoodsId的详细信息,用以展示
                    $.get(baseURL + "goods/goods/designInfo/" + designId, function (r) {
                        vm.designGood = r.designGood;
                    });
                    // 关闭layer
                    layer.close(layer.index);
                    // //绑定designGoodsId到goods上
                    // var goodId = vm.goods.goodsId;
                    // $.get(baseURL + "goods/goods/addDesign/"+goodId+"/"+designId, function(r){
                    //     //添加完毕,重新加载设计商品
                    //     vm.getInfo(goodId);
                    //     //关闭layer
                    //     layer.close(layer.index);
                    // });
                }
            });
        },
        //删除设计服务
        deleteDesign: function () {
            vm.designGood = {};
        },
        //关联设计服务jqGrid查询
        myDesignQuery: function () {
            $("#designJqGrid").jqGrid({
                url: baseURL + 'goods/goods/designList',
                datatype: "json",
                colModel: [
                    {label: 'spu', name: 'goodsId', index: 'goods_id', key: true},
                    {label: '商品编号', name: 'goodsNo', index: 'goods_no',},
                    {label: '商品名', name: 'name', index: 'name',},
                ],
                viewrecords: true,
                height: 385,
                rowNum: 10,
                rowList: [10, 30, 50],
                rownumbers: true,
                rownumWidth: 25,
                autowidth: true,
                multiselect: false,
                pager: "#designJqGridPager",
                jsonReader: {
                    root: "page.list",
                    page: "page.currPage",
                    total: "page.totalPage",
                    records: "page.totalCount"
                },
                prmNames: {
                    page: "page",
                    rows: "limit",
                    order: "order"
                },
                gridComplete: function () {
                    //隐藏grid底部滚动条
                    $("#designJqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
                }
            });
        },
        reloadDesign: function (event) {
            var page = $("#designJqGrid").jqGrid('getGridParam', 'page');
            $("#designJqGrid").jqGrid('setGridParam', {
                page: page,
                postData: {
                    'spu': vm.designQuery.spu,
                    'name': vm.designQuery.name
                },
            }).trigger("reloadGrid");
        },
        //删除图片
        delImage: function (image, fileId) {
            console.info(vm.imageUrls.indexOf(image))
            vm.imageIds.splice(vm.imageIds.indexOf(fileId), 1)
            vm.imageUrls.splice(vm.imageUrls.indexOf(image), 1)
            // alert("imageUrls:" + JSON.stringify(vm.imageUrls) + "imageIds:" + JSON.stringify(vm.imageIds))
        },
        delInfo: function (infoUrl, fileId) {
            vm.infoIds.splice(vm.infoIds.indexOf(fileId), 1)
            vm.infoUrls.splice(vm.infoUrls.indexOf(infoUrl), 1)
            // alert("infoIds:" + JSON.stringify(vm.infoIds) + "infoUrls:" + JSON.stringify(vm.infoUrls))
        },
        //删除视频
        delVideo:function(videoUrl,fileId){
            vm.videoUrl = {};
            vm.good.videoUrl = '';
        },
        //改变默认sku
        changeDefault:function(index){
            for(var i = 0;i<vm.good.itemList.length;i++){
                if(vm.good.itemList[i].defaultProduct == true && i != index){
                    vm.good.itemList[i].defaultProduct = false;
                }
            }

        },
        //-------------------------------------------------报价
        //报价商品参数选择
        quoteAttribute:function(){
            //按商品模板查找其中的规格属性及其规格属性值展示
            // $.get(baseURL + "goods/goodsattribute/getAttributesByTemplateId/" + vm.goodTemplate.templateId, function (r) {
            //     vm.quoteAttributeList = r.attributeList;
            //     vm.quoteCraftAttributeList = r.craftAttributeList;
            //     //弹窗
            //    vm.quoteAttributeLayer = true;
            //     for(var i = 0;i<vm.quoteAttributeList.length;i++){
            //         vm.quoteSelected.push([])
            //     }
            // });
            vm.quoteAttributeLayer = true;
        },
        //机器价格详情
        machinePrice:function(){
            //当身份是小b且发布的是商务印刷的时候,不给看机器
            // if(vm.sellerInfo.sellerType == 0 && vm.categoryEntity.goodsType == 'print'){
            //     alert("供应商暂不发布商务印刷类商品")
            // }
            vm.machinePriceLayer = true;
        },
        //材料价格详情
        materialPrice:function(){
            vm.materialPriceLayer = true;
        },
        //工艺价格详情
        craftPrice:function(){
            if((vm.categoryEntity.goodsType == 'fast' || vm.categoryEntity.goodsType == 'print')){
                vm.craftPriceLayer = true;
            }else{
                var attributeIds =[];
                for(var i = 0 ;i<vm.good.craftAttributes.length;i++){
                    attributeIds.push(vm.good.craftAttributes[i].attribute.attributeId);
                }
                var data={templateId:vm.goodTemplate.templateId,attributeIds:attributeIds.join(",")};
                window.dialogCraftPricVm.setData(data);
            }
        },
        //工艺价格详情
        fastGroupPrice:function(){
            vm.fastGroupPricelayer = true;
        },
        //当默认选中的材料改变时,同时改变其对应的选项
        choiceMaterial:function(index,materialDefaultOptions){
            var quoteTemplate = vm.allQuoteTemplate[index]
            // alert(this.val)
            var list = quoteTemplate.materialAttributeOptionData.materialAttributeOptionList;
            // var key = quoteTemplate.materialAttributeOptionData.materialDefaultOption;
            var key = materialDefaultOptions;
            var tempList = [];
            //遍历list
            for(var i = 0;i < list.length;i++){
                if(list[i].optionKey == key){
                    //找到了被选中的材料所在的分支
                    //遍历list[i].materialSelectedOptionList,找到这些id对应的对象,赋值给quoteTemplate.materialAttributeOptionData.materialDefaultOptionName2List
                    for(var j = 0;j<list[i].materialOptionList.length;j++){
                        //如果list[i].materialOptionList.id在list[i].materialSelectedOptionList里面,放入集合
                        if(list[i].materialSelectedOptionList.indexOf(list[i].materialOptionList[j].id) != -1){
                            //出现
                            tempList.push(list[i].materialOptionList[j]);
                        }
                    }
                    quoteTemplate.materialAttributeOptionData.materialDefaultOptionName2List = tempList;
                    break;
                }
            }
            quoteTemplate.materialAttributeOptionData.materialDefaultOptionName2=null;
        },
        //当某种材料的选中值改变时,若该材料是默认材料时,改变选项列表
        changeMaterial:function(materialAttributeOptionData,materialAttributeOption){
            //判断当前改变值得材料类型,是否是当前默认选中的材料类型
            if(materialAttributeOptionData.materialDefaultOption == materialAttributeOption.optionKey){
                //若是,则判断目前所改变值集合,是否包含选中材料类型的默认类型--->是否重置默认选中材料
                if(materialAttributeOption.materialSelectedOptionList.indexOf(materialAttributeOptionData.materialDefaultOptionName2) == -1){
                    //删除了默认选中的材料-->重置
                    if(materialAttributeOption.materialSelectedOptionList.length ==1 ){
                        //如果只剩下一个选项,则直接选中
                        materialAttributeOptionData.materialDefaultOptionName2 = materialAttributeOption.materialSelectedOptionList[0]
                    }else{
                        materialAttributeOptionData.materialDefaultOptionName2 = null;
                    }
                }
                //更新带选择的默认材料列表
                // materialAttributeOptionData.materialDefaultOptionName2List --->重新赋值
                //materialAttributeOption.materialSelectedOptionList为optionIds,取其对于的tem
                var temp = [];
                for(var i = 0;i<materialAttributeOption.materialOptionList.length;i++){
                    if(materialAttributeOption.materialSelectedOptionList.indexOf(materialAttributeOption.materialOptionList[i].id) != -1){
                        //放入
                        temp.push(materialAttributeOption.materialOptionList[i]);
                    }
                }
                materialAttributeOptionData.materialDefaultOptionName2List = temp;
            }
        },
        //当普通选项的选项值删除了默认时,同步右侧的默认选项
        changeNormal:function(normalAttributeOption){
            var flag = true;
            for(var i = 0;i<normalAttributeOption.normalSelectedTempOptionList.length;i++){
                if(normalAttributeOption.normalSelectedTempOptionList[i].id ==normalAttributeOption.normalDefaultOption ){
                    //此时删除了默认选项重置
                    flag = false;
                }
            }
            if(flag){
                //此时删除了默认选项重置
                if(normalAttributeOption.normalSelectedTempOptionList.length == 1){
                    normalAttributeOption.normalDefaultOption = normalAttributeOption.normalSelectedTempOptionList[0].id;
                }else{
                    normalAttributeOption.normalDefaultOption = null;
                }
            }
        },
        addMaterial:function(event,index,index2){
            console.info("index:"+index+"index2:"+index2)
            //quoteTemplate.materialAttributeOptionData.materialAttributeOptionList
            //添加目的集合
            var select = vm.allQuoteTemplate[index].materialAttributeOptionData.materialAttributeOptionList[index2];
            //被添加的
            var optionKey = select.optionKey;
            var optionName = select.optionName;
            if(event.target.checked){
                vm.allQuoteTemplate[index].materialAttributeOptionData.materialDefaultOptionList.push({optionKey:optionKey,optionName:optionName})
            }else{
                //移除
                var list = vm.allQuoteTemplate[index].materialAttributeOptionData.materialDefaultOptionList
                list.splice(list.indexOf({optionKey:optionKey,optionName:optionName}),1)
            }

        },
        rollbackQuote:function(){
            //报价回滚
            vm.allQuoteTemplate = JSON.parse(JSON.stringify(vm.copyAllQuoteTemplate));
        },

        buildQuoteData:function(){
            //找到没有配价的工艺和材料
            //vm.recordAllQuoteTemplate
            //第一步,处理普通和工艺
            var craftdata = [];
            var materialData = [];
            for (var i = 0;i<vm.recordAllQuoteTemplate.length;i++){
                //定义数据格式:{attributeId:attributeId,optionId:[optionId,optionId]}
                //第一步,处理普通和工艺
                if(vm.recordAllQuoteTemplate[i].normalAttributeOptionList != undefined){
                    for(var j = 0;j<vm.recordAllQuoteTemplate[i].normalAttributeOptionList.length;j++){
                        var data = {};
                        //存放规格id
                        data.attributeId = vm.recordAllQuoteTemplate[i].normalAttributeOptionList[j].id;
                        // var beforeChange = vm.recordAllQuoteTemplate[i].normalAttributeOptionList[j].normalSelectedTempOptionList;
                        var beforeChange = [];
                        for(var k = 0;k<vm.recordAllQuoteTemplate[i].normalAttributeOptionList[j].normalSelectedTempOptionList.length;k++){
                            beforeChange.push(vm.recordAllQuoteTemplate[i].normalAttributeOptionList[j].normalSelectedTempOptionList[k].id);
                        }
                        // var afterChange = vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalSelectedTempOptionList;
                        var afterChange = [];
                        for(var k = 0;k<vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalSelectedTempOptionList.length;k++){
                            afterChange.push(vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalSelectedTempOptionList[k].id);
                        }
                        console.info("beforeChange"+beforeChange)
                        console.info("afterChange"+afterChange)
                        //判断修改前的集合,是否包含修改后的集合每一个元素,若不包含,则将该工艺标记
                        var option = [];
                        for(var k = 0;k<afterChange.length;k++){
                            if(beforeChange.indexOf(afterChange[k]) == -1){
                                //若用户选择后的集合中,存在后台返回数据默认选中之外的数据,则将该条optionId标记为未配置工艺价格的选项
                                option.push(afterChange[k]);
                            }
                            //
                        }
                        data.option = option;
                        if(data.option.length != 0){
                            craftdata.push(data);
                        }
                    }
                }
                //第二步,处理材料
                if(vm.recordAllQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList != undefined){
                    for(var j = 0;j<vm.recordAllQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList.length;j++){
                        var data = {};
                        data.attributeId =vm.recordAllQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[j].id;
                        // materialAttributeOption.materialSelectedOptionList-->系统返回的数据,有材料价格的
                        var afterChange = vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[j].materialSelectedOptionList;
                        var beforChange = vm.recordAllQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[j].materialSelectedOptionList;
                        //判断修改前的材料欧几何,是否包含修改后的每一个材料,若不包含,则将该材料标记
                        var option = [];
                        for(var k = 0;k<afterChange.length;k++){
                            if(beforChange.indexOf(afterChange[k]) == -1){
                                //该材料未配价
                                option.push(afterChange[k])
                            }
                        }
                        data.option = option;
                        if(data.option.length != 0){
                            materialData.push(data);
                        }

                    }
                }
            }
            //循环完毕craftdata--materialData:[{attributeId:attributeId,optionId:[optionId,optionId]},{attributeId:attributeId,optionId:[optionId,optionId]}...
            vm.craftdata = craftdata;
            vm.materialData = materialData;
            //关闭弹窗
            //赋值
            vm.copyAllQuoteTemplate = JSON.parse(JSON.stringify(vm.allQuoteTemplate));
            vm.quoteAttributeLayer = false;
            vm.quotevalidator();
        },
        changePrice:function(value){
            if(value){
                //为true调用pop平台load价格
                vm.loadPrice('pop')
            }else{
                //为false调用紫云网load价格
                vm.loadPrice('ziyun')
            }
        },
        ratioMarketable:function(value){
            if(isBlank(value)){
                return this.$message({
                    type: 'error',
                    message: '系数不能为空!'
                });
            }
            for(var i = 0;i<vm.good.itemList.length;i++){
                if(vm.good.itemList[i].marketable == 'delete'){
                    continue;
                }
                if(isBlank(vm.good.itemList[i].cost)){
                    return this.$message({
                        type: 'error',
                        message: '成本价不能为空!'
                    });
                }
                vm.good.itemList[i].marketPrice = vm.good.itemList[i].cost * value;
                if(!isBlank(vm.good.itemList[i].lCost)){
                    vm.good.itemList[i].lMarketPrice = vm.good.itemList[i].lCost * value;
                }
            }
        },
        loadPrice:function(str){
            var coefficient = null;
            if(str == 'pop' && !isBlank(vm.good.popPriceCoefficient)){
                coefficient  = vm.good.popPriceCoefficient;
                for(var i = 0;i<vm.good.itemList.length;i++){
                    if(!isBlank(vm.good.itemList[i].cost)){
                        vm.good.itemList[i].totalPricePop = vm.good.itemList[i].cost * coefficient;
                        if(!isBlank(vm.good.itemList[i].lCost)){
                            vm.good.itemList[i].expandPricePop = vm.good.itemList[i].lCost * coefficient;
                        }
                    }
                }
                if(!isBlank(vm.price)){
                    vm.good.popPrice = vm.price * vm.good.popPriceCoefficient;
                }
            }else if(str == 'ziyun' && !isBlank(vm.good.ziyunPriceCoefficient)){
                coefficient  = vm.good.ziyunPriceCoefficient;
                for(var i = 0;i<vm.good.itemList.length;i++){
                    if(!isBlank(vm.good.itemList[i].cost)){
                        vm.good.itemList[i].totalPrice = vm.good.itemList[i].cost * coefficient;
                        if(!isBlank(vm.good.itemList[i].lCost)){
                            vm.good.itemList[i].expandPrice = vm.good.itemList[i].lCost * coefficient;
                        }
                    }
                }
                if(!isBlank(vm.price)){
                    vm.good.price = vm.price * vm.good.ziyunPriceCoefficient;
                }
            }
            // if(coefficient != null){
            //     for(var i = 0;i<vm.good.itemList.length;i++){
            //         if(!isBlank(vm.good.itemList[i].cost)){
            //             vm.good.itemList[i].totalPrice = vm.good.itemList[i].cost * coefficient;
            //             if(!isBlank(vm.good.itemList[i].lCost)){
            //                 vm.good.itemList[i].expandPrice = vm.good.itemList[i].lCost * coefficient;
            //             }
            //         }
            //     }
            // }
        },
        countPrice:function(){
            console.info("调用远程接口返回价格")
            var idList = [];
            //默认材料不为空!
            for(var j = 0;j<vm.allQuoteTemplate.length;j++){
                var vo = {};
                //增加分类id和商务印刷和数码快印
                if(vm.categoryEntity.goodsType == 'print'){
                    vo.erpSellerFlag = false
                }else if(vm.categoryEntity.goodsType == 'fast'){
                    vo.erpSellerFlag = true
                }
                vo.categoryId = vm.categoryEntity.categoryId;
                var ids  = [];
                //partsId   categoryId
                if(vm.allQuoteTemplate.length > 1){
                    //有多个部件,则放部件,否则放分类
                    vo.partsId = vm.allQuoteTemplate[j].partsId;
                }else{
                    vo.partsId = vm.allQuoteTemplate[j].categoryId;
                }
                if(JSON.stringify(vm.allQuoteTemplate[j].materialAttributeOptionData) != '{}'){
                    if(!isBlank(vm.allQuoteTemplate[j].materialAttributeOptionData.materialDefaultOptionName2)){
                        ids.push(vm.allQuoteTemplate[j].materialAttributeOptionData.materialDefaultOptionName2);
                    }else{
                        console.info("报错哦")
                    }
                }
                for(var k = 0;k<vm.allQuoteTemplate[j].normalAttributeOptionList.length;k++){
                    if(!isBlank(vm.allQuoteTemplate[j].normalAttributeOptionList[k].normalDefaultOption)){
                        ids.push(vm.allQuoteTemplate[j].normalAttributeOptionList[k].normalDefaultOption);
                    }else{
                        console.info("报错哦")
                    }
                }
                vo.ids = ids;
                idList.push(vo)
            }
            //发送ajax请求
            $.ajax({
                type: "POST",
                url: baseURL + "goods/goods/countPrice",
                contentType: "application/json",
                data: JSON.stringify(idList),
                success: function (r) {
                    if (r.code === 0) {
                        var check = /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/;
                        var singlePriceCountOptionId = vm.getSinglePriceCount();
                        vm.price = r.result / singlePriceCountOptionId;
                        if(vm.good.stageType == 0 || vm.good.stageType == 1){
                            if(check.test(vm.good.ziyunPriceCoefficient)){
                                vm.good.price = vm.price * vm.good.ziyunPriceCoefficient;
                            }
                        }
                        if (vm.good.stageType == 0 || vm.good.stageType == 2){
                            if(check.test(vm.good.ziyunPriceCoefficient)){
                                vm.good.popPrice = vm.price * vm.good.popPriceCoefficient;
                            }
                        }
                    } else {
                        alert(r.msg);
                    }
                }
            });
        },
        quoteVala:function(){
            if (isBlank(vm.good.stageType)) {
                alert("商品上架平台不能为空!");
                return true;
            }
            if (isBlank(vm.good.name)) {
                alert("商品名不能为空!");
                return true;
            }
            if(vm.sellerInfo.sellerId != 20){
                if (isBlank(vm.good.freightId)) {
                    alert("运费模板不能为空!");
                    return true;
                }
                if (isBlank(vm.imageIds) || isBlank(vm.infoIds)) {
                    alert("默认图片和详情图片至少传一张!");
                    return true;
                }
            }else{
                vm.good.hideFlag = 1
                console.info(vm.good.hideFlag)
            }
            //运费模板数字校验
            // var check = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
            var check = /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/;
            //非负数正则
            var check2 = /^\d+(\.{0,1}\d+){0,1}$/;
            var check3 = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
            if(!isBlank(vm.good.popPriceCoefficient) && !check3.test(vm.good.popPriceCoefficient)){
                alert("pop平台利润系数只能填正数")
                return true;
            }
            if(!isBlank(vm.good.ziyunPriceCoefficient) && !check3.test(vm.good.ziyunPriceCoefficient)){
                alert("紫云网利润系数只能填正数")
                return true;
            }
        },
        //标品和大纸的校验
        validator: function () {
            console.log(vm.good);
            // console.log(vm.freightAreaList);
            // console.log(vm.freightAreaList2);
            if (isBlank(vm.good.stageType)) {
                alert("商品上架平台不能为空!");
                return true;
            }
            if(vm.good.goodsType == "paper" && isBlank(vm.good.minBuyNum)){
                alert("商品最小起订量不能为空!");
                return true;
            }
            if (isBlank(vm.good.name)) {
                alert("商品名不能为空!");
                return true;
            }
            if(vm.sellerInfo.sellerId != 20){
                if (isBlank(vm.good.freightId)) {
                    alert("运费模板不能为空!");
                    return true;
                }
                if (isBlank(vm.imageIds) || isBlank(vm.infoIds)) {
                    alert("默认图片和详情图片至少传一张!");
                    return true;
                }
                if (isBlank(vm.good.specificationItems)) {
                    alert("请选择规格属性!");
                    return true;
                }
            }else{
                vm.good.hideFlag = 1
                console.info(vm.good.hideFlag)
            }
            //运费模板数字校验
            // var check = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
            var check = /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/;
            //非负数正则
            var check2 = /^\d+(\.{0,1}\d+){0,1}$/;
            var check3 = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
            if(!isBlank(vm.good.popPriceCoefficient) && !check3.test(vm.good.popPriceCoefficient)){
                alert("pop平台利润系数只能填正数")
                return true;
            }
            if(!isBlank(vm.good.ziyunPriceCoefficient) && !check3.test(vm.good.ziyunPriceCoefficient)){
                alert("紫云网利润系数只能填正数")
                return true;
            }
            // if (!(check.test(vm.freightTemplate.firstUnit) && check.test(vm.freightTemplate.firstPrice) && check.test(vm.freightTemplate.continueUnit) && check.test(vm.freightTemplate.continuePrice))) {
            //     alert("模板参数只能是正数!")
            //     return true;
            // }
            //vm.good.itemList : [{spec: {},cra: {},store: '',unit: '',minBuyNum: '',marketable: 'puton',weight: '',totalPrice: '',
            //                 marketPrice: '',expandPrice: '',lMarketPrice: '',cost: '',lCost: '',defaultProduct: false}]
            for(var i = 0;i < vm.good.itemList.length;i++){
                var item = vm.good.itemList[i];
                //是否删除判断
                if(item.marketable == 'delete'){
                    //若删除则不走判断
                    item.unit = '无';
                }else{
                    if(!(check.test(item.cost))){
                        alert("成本价只能是正数!")
                        return true;
                    }
                    if(!isBlank(item.marketPrice) && !check.test(item.marketPrice)){
                        alert("市场价若不为空,则必须是是正数!")
                        return true;
                    }
                    if(!check2.test(item.weight)){
                        alert("克重只能是非负数")
                        return true;
                    }
                    // && check.test(item.totalPrice)
                    if((vm.good.stageType == 0 || vm.good.stageType == 1)&& !check.test(item.totalPrice)){
                        alert("紫云价格信息不全!")
                        return true;
                    }
                    if((vm.good.stageType == 0 || vm.good.stageType == 2)&& !check.test(item.totalPricePop)){
                        alert("pop价格信息不全!")
                        return true;
                    }

                    if(!isBlank(item.minBuyNum) && !check.test(item.minBuyNum)){
                        alert("最小起订量只能为空或正数!")
                        return true;
                    }
                    if(!vm.good.noStore && !(check.test(item.store))){
                        alert("禁止无库存销售则必须配置库存数!")
                        return true;
                    }
                    if(!vm.good.noStore){
                        //禁止无库存销售时,库存数量大于起订量
                        if(item.minBuyNum > item.store){
                            alert("禁止无库存销售时,库存数量大于起订量!")
                            return true;
                        }
                    }
                    //若是大纸平板则校验如下
                    if(vm.categoryEntity.goodsType == 'paper' && vm.good.isUnit == '1'){
                        if(!(check.test(item.expandPrice)&& check.test(item.lMarketPrice)&& check.test(item.lCost))){
                            alert("大纸平板属性参数只能是正数!")
                            return true;
                        }
                    }
                }
            }
        },
        quotevalidator:function(){
            // //在这里做模板规格必须都选判断
            // //报价类型的判断
            // if(vm.categoryEntity.goodsType =='material'||vm.categoryEntity.goodsType =='fast'||vm.categoryEntity.goodsType =='print'){
            //     //默认材料不为空!
            //     for(var j = 0;j<vm.allQuoteTemplate.length;j++){
            //         if(JSON.stringify(vm.allQuoteTemplate[j].materialAttributeOptionData) != '{}'){
            //             if(isBlank(vm.allQuoteTemplate[j].materialAttributeOptionData.materialDefaultOptionName2)){
            //                 alert("材料必须选一种!")
            //                 return true;
            //             }
            //         }
            //         for(var k = 0;k<vm.allQuoteTemplate[j].normalAttributeOptionList.length;k++){
            //             if(isBlank(vm.allQuoteTemplate[j].normalAttributeOptionList[k].normalDefaultOption)){
            //                 alert("规格必须全满!")
            //                 return true;
            //             }
            //         }
            //     }
            // }
            //获得所有的选项(包括规格选项)
            var ids = [];
            for(var i  = 0 ;i <vm.allQuoteTemplate.length;i++){
                for(var ii = 0;ii <vm.allQuoteTemplate[i].normalAttributeOptionList.length;ii++){
                    for(var iii = 0;iii <vm.allQuoteTemplate[i].normalAttributeOptionList[ii].normalSelectedTempOptionList.length;iii++){
                        ids.push(vm.allQuoteTemplate[i].normalAttributeOptionList[ii].normalSelectedTempOptionList[iii].id);
                    }
                }
            }
            //报价类的校验工艺价
            $.ajax({
                type: "POST",
                url: baseURL + "goods/goods/quotePrice",
                contentType: "application/json",
                async:false,
                data: ids.join(","),
                success: function (r) {
                    if(r.result == "ok"){
                        // alert("ok")
                        vm.canPush =  false;
                        return false;
                    }else if(r.result == "error"){
                        alert("报价工艺参数不全")
                        vm.canPush =  true;
                        return true;
                    }
                }
            });
            if (vm.categoryEntity.goodsType == 'print'){
                return vm.machineValidator();
            }
            if(vm.categoryEntity.goodsType == 'fast'){
                return vm.fastValidator();
            }
            return false;
        },
        machineValidator:function(){
            //报价类的校验机器价
            //颜色选项
            var colorOptionIds = [];
            //尺寸选项
            var sizeOptionIds = [];
            //克重选项
            var weightOptionIds = [];
            for(var i = 0;i<vm.allQuoteTemplate.length;i++){
                for(var ii=0 ;ii<vm.allQuoteTemplate[i].normalAttributeOptionList.length;ii++){
                    if(vm.allQuoteTemplate[i].normalAttributeOptionList[ii].attributeName == '颜色'){
                        for(var iii = 0;iii<vm.allQuoteTemplate[i].normalAttributeOptionList[ii].normalSelectedTempOptionList.length;iii++){
                            colorOptionIds.push(vm.allQuoteTemplate[i].normalAttributeOptionList[ii].normalSelectedTempOptionList[iii].id);
                        }
                    }
                    if(vm.allQuoteTemplate[i].normalAttributeOptionList[ii].attributeName == '成品尺寸'){
                        for(var iii = 0;iii<vm.allQuoteTemplate[i].normalAttributeOptionList[ii].normalSelectedTempOptionList.length;iii++){
                            sizeOptionIds.push(vm.allQuoteTemplate[i].normalAttributeOptionList[ii].normalSelectedTempOptionList[iii].id);
                        }
                    }
                }
                if(JSON.stringify(vm.allQuoteTemplate[i].materialAttributeOptionData) != '{}'){
                    for(var j = 0;j<vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList.length;j++){
                        // for(var jj = 0;jj<vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[j].materialSelectedOptionList.length;jj++){
                        Array.prototype.push.apply(weightOptionIds, vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[j].materialSelectedOptionList);
                        // }
                    }
                }
            }
            console.info("colorOptionIds:"+colorOptionIds);
            console.info("sizeOptionIds:"+sizeOptionIds);
            console.info("weightOptionIds:"+weightOptionIds);
            var printPriceVo = {};
            printPriceVo.colorOptionIds = colorOptionIds;
            printPriceVo.sizeOptionIds = sizeOptionIds;
            printPriceVo.weightOptionIds = weightOptionIds;
            $.ajax({
                type: "POST",
                url: baseURL + "goods/goods/verifyPrintPrice",
                contentType: "application/json",
                async:false,
                data: JSON.stringify(printPriceVo),
                success: function (r) {
                    if(r.result == "ok"){
                        // alert("ok")
                        vm.canPush =  false;
                        vm.countPrice();
                        return false;
                    }else{
                        alert("报价工艺参数不全"+r.result)
                        vm.canPush =  true;
                        return true;
                    }
                }
            });
        },
        // dataMigration:function(){
        //     this.$confirm('该功能仅做测试阶段迁移数据使用,是否继续?', '提示', {
        //         confirmButtonText: '确定',
        //         cancelButtonText: '取消',
        //         type:
        //     }).then(() => {
        //         $.ajax({
        //             type: "POST",
        //             url: baseURL + "goodsCopyNew/goodscopynew/dataMigration",
        //             contentType: "application/json",
        //             success: function (r) {
        //                 if (r.code === 0) {
        //                     alert("返回回调")
        //                 } else {
        //                     alert(r.msg);
        //                 }
        //             }
        //         });
        //         this.$message({
        //             type: 'success',
        //             message: '删除成功!'
        //         });
        //     }).catch(() => {
        //         this.$message({
        //             type: 'info',
        //             message: '已取消删除'
        //         });
        //     });
        // },
        //数码快印组合计价校验
        fastValidator:function(){
            //直接将所有选项全部按部件封装到后台校验
            var fastPriceVoList = [];
            for(var i = 0;i<vm.allQuoteTemplate.length;i++){
                var fastPriceVo = {};
                var selectedAttributeIds = [];
                var allSelectedOptionIds = [];
                for(var ii = 0;ii<vm.allQuoteTemplate[i].normalAttributeOptionList.length;ii++){
                    //可能会空
                    for(var iii = 0;iii<vm.allQuoteTemplate[i].normalAttributeOptionList[ii].normalSelectedTempOptionList.length;iii++){
                        selectedAttributeIds.push(vm.allQuoteTemplate[i].normalAttributeOptionList[ii].normalSelectedTempOptionList[iii].id);
                        //放入全部选项中
                        allSelectedOptionIds.push(vm.allQuoteTemplate[i].normalAttributeOptionList[ii].normalSelectedTempOptionList[iii].id);
                    }
                }
                fastPriceVo.selectedAttributeIds = selectedAttributeIds;
                //若材料不为空,则遍历
                if(JSON.stringify(vm.allQuoteTemplate[i].materialAttributeOptionData) != '{}'){
                    var selectedMaterialIds = [];
                    for(var ii = 0;ii<vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList.length;ii++){
                        // var materialMap = {};
                        var optionKey = vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[ii].optionKey;
                        var materialIds = [];
                        for(var iii = 0;iii<vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[ii].materialSelectedOptionList.length;iii++){
                            // materialIds.push(vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[ii].materialSelectedOptionList[iii]);
                            selectedMaterialIds.push(vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[ii].materialSelectedOptionList[iii]);
                            allSelectedOptionIds.push(vm.allQuoteTemplate[i].materialAttributeOptionData.materialAttributeOptionList[ii].materialSelectedOptionList[iii]);
                        }
                        // materialMap.optionKey = optionKey;
                        // materialMap.materialIds = materialIds;
                        // selectedMaterialIds[optionKey] = materialIds;
                    }
                    fastPriceVo.selectedMaterialIds = selectedMaterialIds;

                }
                fastPriceVo.allSelectedOptionIds = allSelectedOptionIds;
                fastPriceVoList.push(fastPriceVo);
            }
            for(var j = 0;j<fastPriceVoList.length;j++){
                console.info("selectedAttributeIds:"+fastPriceVoList[j].selectedAttributeIds);
                console.info("selectedMaterialIds:"+JSON.stringify(fastPriceVoList[j].selectedMaterialIds));
            }
            //发送ajax请求校验数据结果
            $.ajax({
                type: "POST",
                url: baseURL + "goods/goods/verifyFastPrice",
                contentType: "application/json",
                async:false,
                data:JSON.stringify(fastPriceVoList),
                success: function (r) {
                    if(r.result == "ok"){
                        alert("校验通过")
                        vm.canPush =  false;
                        vm.countPrice();
                        return false;
                    }else{
                        alert("快印校验不通过:"+r.result)
                        vm.canPush =  true;
                        return true;
                    }
                }
            });
        },
        //优化
        //一键全选
        selectAllOption:function(row){
            row.optionSelectedList = row.goodsOptionList;
        },
        allSelect:function(str){
            if(vm.good.itemList.length > 1){
                for(var i = 1;i<vm.good.itemList.length;i++){
                    vm.good.itemList[i][str] = vm.good.itemList[0][str];
                }
            }
        },
        oneSet:function(str){
            this.$prompt('请输入市场价系数', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(({ value }) => {
                vm.ratioMarketable(value);
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消输入'
                });
            });
        },
        //一键设置紫云网售价
        oneSetZiyunPop:function(str){
            // vm.loadPrice('pop')
            this.$prompt('请输入'+ str +'利润系数', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
            }).then(({ value }) => {
                if(str == '紫云'){
                    vm.good.ziyunPriceCoefficient = value;
                    vm.loadPrice('ziyun')
                }else{
                    vm.good.popPriceCoefficient = value;
                    vm.loadPrice('pop')

                }
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消输入'
                });
            });

        },
        optionDialog:function(row){
            vm.addPrivateOption.attributeId = row.attributeId
            vm.addOptionDialog = true;
        },
        //保存增加选项
        savePrivateOption:function(){
            if(!isBlank(vm.goodTemplate.influenceSkuTotalPrice) && vm.addPrivateOption.attributeId == vm.goodTemplate.influenceSkuTotalPrice) {
                var re = /^[0-9]+$/;
                if (!re.test(vm.addPrivateOption.optionValue)) {
                    alert("该选项影响算价,请修正选项值为数字!")
                    return;
                }
            }
            //发送ajax请求生成私有选项
            $.ajax({
                type: "POST",
                url: baseURL + "goods/goodsattribute/newOption",
                contentType: "application/json",
                data:JSON.stringify(vm.addPrivateOption),
                // data:JSON.stringify(attribute),
                success: function (r) {
                    //重新加载规格选项
                    // vm.getAttributesByTemplateId();
                    if(r.code == 0){
                        if(r.goodsOptionEntity != null){
                            for(var i = 0;i<vm.attributeList.length;i++){
                                if(vm.attributeList[i].attributeId == r.goodsOptionEntity.attributeId){
                                    vm.attributeList[i].goodsOptionList.push(r.goodsOptionEntity);
                                }
                            }
                            vm.copyAttributeList = JSON.parse(JSON.stringify(vm.attributeList));
                            vm.copyCraftAttributeList = JSON.parse(JSON.stringify(vm.craftAttributeList));
                        }else{
                            alert("新增选项异常,请联系管理员")
                        }
                    }
                }
            })
            vm.addOptionDialog = false;
        },
        //取消保存选项
        cancelPrivateOption:function(){
            //重置值
            vm.addPrivateOption.attributeId = null;
            vm.addPrivateOption.optionName = null;
            vm.addPrivateOption.optionValue = null;
            vm.addOptionDialog = false;
        },
        //提取报价算价数量参数--返回默认数量
        getSinglePriceCount(){
            if(vm.allQuoteTemplate != null){
                for(var i = 0;i<vm.allQuoteTemplate.length;i++){
                    for(var j = 0;j <vm.allQuoteTemplate[i].normalAttributeOptionList.length;j++){
                        if(vm.allQuoteTemplate[i].normalAttributeOptionList[j].attributeTypeValue == 'quantity'){
                            for(var k = 0;k<vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalOptionList.length;k++){
                                if(vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalOptionList[k].id == vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalDefaultOption){
                                    return vm.allQuoteTemplate[i].normalAttributeOptionList[j].normalOptionList[k].optionName;
                                }
                            }
                        }
                    }
                }
            }
        },
        //------------------------------
        delRow: function (index, stepPriceList) {
            stepPriceList.splice(index, 1);
        },
        addStepPriceList: function () {
            vm.stepPriceList.push({startPrice: null, endPrice: null, coefficient: null})
        },
        openStepPrice:function(type){
            vm.stepType = type;
            if(type == 'ziyun'){
                if(!isBlank(vm.good.stepPrice)){
                    vm.stepPriceList = JSON.parse(vm.good.stepPrice);
                }
                vm.priceDialog = true;
            }else if(type == 'pop'){
                if(!isBlank(vm.good.popStepPrice)){
                    vm.stepPriceList = JSON.parse(vm.good.popStepPrice);
                }
                vm.priceDialog = true;
            }else{
                alert("阶梯价展示异常")
            }
        },
        closePriceDialog: function () {
            //将阶梯价清空
            vm.stepPriceList = [];
        },
        savePrice: function () {
            if (this.stepPriceValidator()) {
                return;
            }
            if(vm.stepType == 'ziyun'){
                if(!isBlank(vm.stepPriceList)){
                    vm.good.stepPrice = JSON.stringify(vm.stepPriceList);
                }
                vm.priceDialog = false;
            }else if(vm.stepType == 'pop'){
                if(!isBlank(vm.stepPriceList)){
                    vm.good.popStepPrice = JSON.stringify(vm.stepPriceList);
                }
                vm.priceDialog = false;
            }else{
                alert("阶梯价保存异常")
            }
        },
        stepPriceValidator:function(){
            for(var i = 0;i<vm.stepPriceList.length;i++){
                var stepPrice = vm.stepPriceList[i];
                if(isBlank(stepPrice.startPrice)){
                    alert("第"+(i+1)+"行阶梯价起始价格为空,请检查!");
                    return true;
                }
                if(isBlank(stepPrice.endPrice)){
                    alert("第"+(i+1)+"行阶梯价结束价格为空,请检查!");
                    return true;
                }
                if(isBlank(stepPrice.coefficient)){
                    alert("第"+(i+1)+"行阶梯价利润系数为空,请检查!");
                    return true;
                }
            }
            return false;
        }
    }
});
